package top.kaoshanji.p1ch08a;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.HashMap;
import java.util.Map;

/**
 * 代码清单-p1ch08a-146页a：AppListener类
 * @author kaoshanji
 * ^_^
 * create time 2025/4/7 15:58
 */
@WebListener
public class AppListener implements ServletContextListener {

    // 容器启动时触发
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        ServletContext servletContext = sce.getServletContext();

        Map<String, String> countries = new HashMap<>();
        countries.put("ca", "Canada");
        countries.put("us", "United States");

        servletContext.setAttribute("countries", countries);

    }

}
